<template>
  <el-table-column
    :key="code"
    :label="name"
    :fixed="false"
    align="center"
    width="300"
  >
    <template #default="scope">
      <el-tag v-for="label in parseData(scope.row[code])" :key="label.id" size="mini" type="primary">
        {{ label.name }}
      </el-tag>
    </template>
  </el-table-column>
</template>

<script>
export default {
  props: {
    code: {
      type: String,
      default: ''
    },
    name: {
      type: String,
      default: ''
    }
  },
  methods: {
    /**
     * 解析数据
     * @param data
     * @returns {any|*[]}
     */
    parseData(data) {
      try {
        return JSON.parse(data)
      } catch (err) {
        return []
      }
    }
  }
}
</script>
